package com.bwie.controller;
import com.bwie.pojo.Hotel;
import com.bwie.service.HotelService;
import com.bwie.utils.R;
import io.jsonwebtoken.Jwts;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.PostConstruct;
import java.util.List;

/**
* (t_hotel)表控制层
*
* @author xxxxx
*/
@RestController
@Api(tags = "酒店列表")
@RequestMapping("/hotel/index")
public class HotelController {
/**
* 服务对象
*/
    @Autowired
    private HotelService hotelService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    @ApiOperation("查询酒店列表")
    @PostMapping("/selectHotel")
    public R selectHotel(){
        String token = redisTemplate.opsForValue().get("token");
        Long id = Jwts.parser().setSigningKey("bwie").parseClaimsJws(token).getBody().get("id", Long.class);
        List<Hotel> hotelList = hotelService.selectAll(id);
        return R.OK(hotelList);
    }
    @ApiOperation("上传图片")
    @PostMapping("/uploadImage")
    public R uploadImage(@RequestPart MultipartFile file){
        return hotelService.uploadImage(file);
    }

    @ApiOperation("修改酒店信息")
    @PostMapping("/updateHotel")
    public R updateHotel(@RequestBody Hotel hotel){
        return hotelService.updateHotel(hotel);
    }

}
